<template>
  <div class="app-container">
    <div class="filter-container">
      <el-page-header @back="backUp" class="backUp" :content="type_name+'-属性列表'"></el-page-header>
      <el-button type="primary" icon="el-icon-plus" @click="handleCreateAttr">添加属性</el-button>
    </div>
    <el-table
      :data="data"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      border
      default-expand-all
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >
      <el-table-column prop="value_name" label="属性名称" align='center'/>
      <el-table-column label="显示状态" align='center'>
        <template slot-scope="item">
          {{item.row.show_type==1?'司机':item.row.show_type==2?'非司机':item.row.show_type==3?'企业':'全部'}}
        </template>
      </el-table-column>
      <el-table-column label="属性值类型" align='center'>
        <template slot-scope="item">
          {{item.row.value_type==1?'上传图片':item.row.value_type==2?'选择地址':item.row.value_type==3?'输入框':'无'}}
        </template>
      </el-table-column>
      <el-table-column prop="value_key" label="类型key" align='center'/>
      <el-table-column label="是否自定义" align='center'>
        <template slot-scope="item">
          {{item.row.is_custom==1?'是':'否'}}
        </template>
      </el-table-column>
      <el-table-column label="排序" align='center'>
        <template slot-scope="item">
          <el-input v-model="item.row.sort" type='number' @blur="attrUpdate(item.row,'sort')"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" width='200' align='center'>
        <template slot-scope="item">
          <el-link type="primary" class="table_btn" @click="handleUpdate(item.row)" :underline="false"><i class="iconfont icon-bianji"></i>编辑</el-link>
          <el-link type="danger" class="table_btn" @click="handleDelete(item.row.value_id)" :underline="false"><i class="iconfont icon-lajitong1"></i>删除</el-link>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      class="pagination-container"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="paginate.current"
      :hide-on-single-page='isHideSingle'
      :page-sizes="paginate.sizes"
      :page-size="paginate.limit"
      :layout="paginate.layout"
      :total="paginate.total"/>
  </div>
</template>

<script>
import formOperate from '@/layout/mixin/formOperate'
export default {
  name: 'Index',
  mixins: [formOperate],
  data() {
    return {
      url:'/profession/admin/tagValue',
      pk:'value_id',
      queryParam:{
        page:1,
        page_index:10,
        type_id:''
      },
      parentOptions:[],
      labelType:0,
      type_name:'',
    }
  },
  created() {
    this.queryParam.type_id = this.$route.query.type_id
    this.type_name = this.$route.query.name
  },
  methods: {
    backUp() {
      this.$router.go(-1)
    },
    // 修改排序
    attrUpdate(item,type) {
      this.id = item.value_id
      let param = {}
      param[type] = item[type]
      this.$http.put(this.url + '/' + this.id, param).then((response) => {
        this.handleResponse(response)
      })
    },
    // 添加属性
    handleCreateAttr() {
      this.$router.push({
        path:'/talents/addAttr',
        query:{type_id:this.queryParam.type_id}
      })
    },
    // 修改属性
    handleUpdate(row) {
      this.$router.push({
        path:'/talents/addAttr',
        query:{id:row.value_id,type_id:this.queryParam.type_id}
      })
    }
  }
}
</script>